import { IPSAppDEField } from '../../app/dataentity/ipsapp-defield';
import { IPSCodeList } from '../../codelist/ipscode-list';
import { IPSDETreeNodeDataItem } from './ipsdetree-node-data-item';
import { PSDataItemImpl } from '../../data/psdata-item-impl';

export class PSDETreeNodeDataItemImpl extends PSDataItemImpl implements IPSDETreeNodeDataItem {
  get cLConvertMode(): 'NONE' | 'FRONT' | 'BACKEND' {
    return this.M.cLConvertMode;
  }

  get defaultValue(): string {
    return this.M.defaultValue;
  }

  protected frontpscodelist: IPSCodeList | null = null;

  getFrontPSCodeList(): IPSCodeList | null {
    if (this.frontpscodelist != null) return this.frontpscodelist;
    const value = this.M.getFrontPSCodeList;
    if (value == null) {
      return null;
    }
    this.frontpscodelist = this.getPSModel4('codelist.IPSCodeList', value, 'getFrontPSCodeList') as IPSCodeList;
    return this.frontpscodelist;
  }

  get frontPSCodeList(): IPSCodeList | null {
    return this.getFrontPSCodeList();
  }

  getFrontPSCodeListMust(): IPSCodeList {
    const value = this.getFrontPSCodeList();
    if (value == null) {
      throw new Error('未指定前端代码表');
    }
    return value;
  }

  protected psappdefield: IPSAppDEField | null = null;

  getPSAppDEField(): IPSAppDEField | null {
    if (this.psappdefield != null) return this.psappdefield;
    const value = this.M.getPSAppDEField;
    if (value == null) {
      return null;
    }
    this.psappdefield = this.getPSModel4('app.dataentity.IPSAppDEField', value, 'getPSAppDEField') as IPSAppDEField;
    return this.psappdefield;
  }

  get psAppDEField(): IPSAppDEField | null {
    return this.getPSAppDEField();
  }

  getPSAppDEFieldMust(): IPSAppDEField {
    const value = this.getPSAppDEField();
    if (value == null) {
      throw new Error('未指定应用实体属性');
    }
    return value;
  }

  get privilegeId(): string {
    return this.M.privilegeId;
  }

  get scriptCode(): string {
    return this.M.scriptCode;
  }

  get customCode(): boolean {
    return this.M.customCode != null ? this.M.customCode : false;
  }

  get dataAccessAction(): boolean {
    return this.M.dataAccessAction != null ? this.M.dataAccessAction : false;
  }

  get enableItemPriv(): boolean {
    return this.M.enableItemPriv != null ? this.M.enableItemPriv : false;
  }

  get cls(): string {
    return 'PSDETreeNodeDataItemImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'control.tree.IPSDETreeNodeDataItem') return true;
    return super.instanceof(cls);
  }
}
